<?php

namespace app\admin\controller\catalog;

use app\common\controller\Backend;

/**
 * 抓取記錄
 *
 * @icon fa fa-users
 */
class CrawlEmail extends Backend
{

    /**
     * @var \app\common\model\Email
     */
    protected $model = null;
    protected $merchField = true;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('CrawlEmails');
    }
    public function index($crawl_id = null){
        if ($this->request->isAjax()) {
            $map = [];
            $map['crawl_id'] = intval($crawl_id);
            list($where, $sort, $order, $offset, $limit) = $this->buildparams('email');
            $list = $this->model
                ->where($where)
                ->where($map)
                ->order($sort, $order)
                ->paginate($limit);

            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        $this->assignconfig('crawl_id',intval($crawl_id));
        return $this->view->fetch();
    }
    public function add()
    {
        if ($this->request->isPost()) {
            $this->token();
        }
        return parent::add();
    }

    public function edit($ids = null)
    {
        if ($this->request->isPost()) {
            $this->token();
        }
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        return parent::edit($ids);
    }

}
